/**
 * mainwindow.cpp is part of %PROJECTNAME%.
 *
 * %PROJECTNAME% is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * %PROJECTNAME% is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with %PROJECTNAME%.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDockWidget>
#include <QTabWidget>
#include <QTableWidget>

MainWindow::MainWindow( QWidget * parent ) :
    QMainWindow( parent ),
    m_ui( new Ui::MainWindow ),
    m_tasksDockWidget( 0 ),
    m_resourcesDockWidget( 0 ),
    m_tabbedWidget( 0 )

{
    m_ui->setupUi( this );
    CreateMenus();
    CreateToolBars();
    CreateDockWidgets();
    CreateCenterWidget();
    CreateStatusBar();
}

MainWindow::~MainWindow()
{
    Clear();
}

void MainWindow::Clear()
{
    if( m_ui )
        delete m_ui;
    m_ui = 0;

    if( m_tasksDockWidget )
        delete m_tasksDockWidget;
    m_tasksDockWidget = 0;

    if( m_resourcesDockWidget )
        delete m_resourcesDockWidget;
    m_resourcesDockWidget = 0;

    if( m_tabbedWidget )
        delete m_tabbedWidget;
    m_tabbedWidget = 0;
}

void MainWindow::CreateMenus()
{

}

void MainWindow::CreateToolBars()
{

}

void MainWindow::CreateDockWidgets()
{
    CreateTasksDockWidget();
    CreateResourcesDockWidget();
}

void MainWindow::CreateTasksDockWidget()
{
    m_tasksDockWidget = new QDockWidget( tr( "ID_TASKS_WIDGET" ), this );
    if( m_tasksDockWidget )
    {
        m_tasksDockWidget->setAllowedAreas( Qt::AllDockWidgetAreas );
        m_tasksDockWidget->setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
        m_tasksDockWidget->setWidget( new QTableWidget( m_tasksDockWidget ) );

        addDockWidget( Qt::LeftDockWidgetArea, m_tasksDockWidget );
    }
}

void MainWindow::CreateResourcesDockWidget()
{
    m_resourcesDockWidget = new QDockWidget( tr( "ID_RESOURCES_WIDGET" ), this );
    if( m_resourcesDockWidget )
    {
        m_resourcesDockWidget->setAllowedAreas( Qt::AllDockWidgetAreas );
        m_resourcesDockWidget->setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
        m_resourcesDockWidget->setWidget( new QTableWidget( m_resourcesDockWidget ) );

        addDockWidget( Qt::RightDockWidgetArea, m_resourcesDockWidget );
    }
}

void MainWindow::CreateCenterWidget()
{
    m_tabbedWidget = new QTabWidget( this );
    if( m_tabbedWidget )
    {
        m_tabbedWidget->setIconSize( QSize( 16, 16 ) );
        m_tabbedWidget->setTabsClosable( false );
        // m_tabbedWidget->insertTab( index, QWidget *, QIcon, QString );

        setCentralWidget( m_tabbedWidget );
    }
}

void MainWindow::CreateStatusBar()
{

}
